package testing._main;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.io.IOException;

import javax.swing.JFrame;

//import testing.control.ModuleMouse;
import testing.control.TestKeyboardControl;
import testing.control.TestMouseControl;
//import testing.data.BoxAndCircle;
import testing.manager.BoxAndCircleRunner;
import testing.manager.FlashingRectangleRunner;
import testing.manager.GenericRunner;
import testing.module.CanyonWalls;
import testing.module.DrawAnyShapeTest;
import testing.module.IntroScreen;
//import testing.module.DrawCircleTest;
import utilities.control.keyboard.Keyboard;
import utilities.control.mouse.Mouse;
import utilities.display.shapes.definedshapes.DrawPolygon;
import utilities.exceptions.JFrameNameUsedException;
import utilities.manager.Runner;
import utilities.manager.JFrameManager;
import utilities.module.Module;

public class JFrameTest 
{
	private static final String JFRAME_TEST_NAME = "TEST";
	
	public static void main(String[] args) throws Exception
	{
		JFrame test;
		
		try 
		{
			//JFrameManager.makeWindow(JFRAME_TEST_NAME, new Dimension(400, 300), Color.white, true);
			JFrameManager.makeWindow(JFRAME_TEST_NAME, new Dimension(500, 700), Color.white, true);
		}
		catch (JFrameNameUsedException e) 
		{
			e.printStackTrace();
			System.out.println(e.toString());
		}
		
		if((test = JFrameManager.getGameWindow(JFRAME_TEST_NAME)) == null)
		{
			System.out.println("Failed to create a window!");
			return;
		}
		
		//testFlashingRectangleGame(test);
		//testBoxAndCircleGame(test);
		//testGenericRunner(test);
		testIntroScreen(test);
		//testWallGeneration(test);
	}

	public static void testFlashingRectangleGame(JFrame test) 
	{
		Keyboard kc = new TestKeyboardControl(null);
		Mouse mc = new TestMouseControl(null);

		Runner testMe = new FlashingRectangleRunner(test.getWidth(), test.getHeight(), Color.white);
		
		testMe.start();
		test.add(testMe);

		// Registers listeners to parents correctly
		kc.registerParent(test);
		mc.registerParent(test);
		
		// Should have error messages come up; each Keyboard and Mouse may only have one parent
		// at any time.
		kc.registerParent(test);
		mc.registerParent(test);
	}

	public static void testBoxAndCircleGame(JFrame test) 
	{
		//Keyboard kc = new TestKeyboardControl(null);
		//Mouse mc = new ModuleMouse(null);
		//Mouse mc = new ModuleMouse(test);

		//GameRunner testMe = new BoxAndCircleRunner(test.getWidth(), test.getHeight(), Color.white);
		BoxAndCircleRunner testMe = new BoxAndCircleRunner(test.getWidth(), test.getHeight(), Color.white, test);
		
		testMe.start();
		test.add(testMe);
		
		test.addKeyListener(testMe.getModule());
		test.addMouseMotionListener(testMe.getModule());

		// Registers listeners to parents correctly
		//kc.registerParent(test);
		//mc.registerParent(test);
		
		// Should have error messages come up; each Keyboard and Mouse may only have one parent
		// at any time.
		//kc.registerParent(test);
		//mc.registerParent(test);
	}

	public static void testGenericRunner(JFrame test)
	{
		DrawPolygon trapezoid = new DrawPolygon(Color.black, new BasicStroke(1), null, Color.cyan, null);
		
		// Add four points of trapezoid
		int x1 = 50;
		int y1 = 75;
		
		trapezoid.addPoint(x1, y1);
		
		int x2 = 50;
		int y2 = 175;
		
		trapezoid.addPoint(x2, y2);
		
		int x3 = 250;
		int y3 = 175;
		
		trapezoid.addPoint(x3, y3);
		
		int x4 = 150;
		int y4 = 75;
		
		trapezoid.addPoint(x4, y4);
		
		//GameModule mod = new DrawCircleTest(test.getWidth() / 2, test.getHeight() / 2, 100);
		Module mod = new DrawAnyShapeTest(trapezoid);
		
		Runner testMe = new GenericRunner(test.getWidth(), test.getHeight(), Color.white, mod);
		
		testMe.start();
		test.add(testMe);
	}

	public static void testIntroScreen(JFrame test) throws IOException
	{
		Module mod = new IntroScreen();
		
		Runner testMe = new GenericRunner(test.getWidth(), test.getHeight(), Color.white, mod);
		
		testMe.start();
		test.add(testMe);
	}

	public static void testWallGeneration(JFrame test) throws IOException
	{
		Module mod = new CanyonWalls();
		
		Runner testMe = new GenericRunner(test.getWidth(), test.getHeight(), Color.white, mod);
		
		testMe.start();
		test.add(testMe);
		
		test.addKeyListener(testMe);
		test.addMouseListener(testMe);
	}
}
